//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nccloud.web.uapbd.ref.pm;

import nc.vo.pmpub.project.ProjectHeadVO;
import nccloud.commons.lang.StringUtils;
import nccloud.framework.web.processor.refgrid.RefQueryInfo;
import nccloud.framework.web.processor.reftree.TreeRefQueryInfo;
import nccloud.framework.web.ui.meta.RefMeta;

public class HrpbmProjectGridRef extends ProjectDefaultGridRef {
    private boolean isfilter = false;
    private Integer year;
    private String pk_topbudgettype;
    private String pk_budgetdept;

    public HrpbmProjectGridRef() {
    }

    public RefMeta getRefMeta(RefQueryInfo refQueryInfo) {
        RefMeta ret = new RefMeta();
        ret.setCodeField("project_code");
        ret.setNameField("project_name");
        ret.setPkField("pk_project");
        ret.setPidField("pk_eps");
        ret.setMutilLangNameRef(true);
        ret.setTableName(ProjectHeadVO.getDefaultTableName());
        ret.setExtraFields(new String[]{"project_code", "project_name", "project_sh_name", "pk_eps"});
        ret.setFullTxtTabName(ProjectHeadVO.getDefaultTableName());
        return ret;
    }

    public String getExtraSql(RefQueryInfo paramRefQueryInfo, RefMeta paramRefMeta) {
        String extraSql = super.getExtraSql(paramRefQueryInfo, paramRefMeta);
        this.isfilter = Boolean.valueOf((String)paramRefQueryInfo.getQueryCondition().get("isfilter"));
        this.pk_topbudgettype = (String)paramRefQueryInfo.getQueryCondition().get("pk_topbudgettype");
        this.pk_budgetdept = (String)paramRefQueryInfo.getQueryCondition().get("pk_budgetdept");
        boolean isYear = StringUtils.isNumeric((CharSequence)paramRefQueryInfo.getQueryCondition().get("year"));
        boolean isBoolean = Boolean.valueOf((String)paramRefQueryInfo.getQueryCondition().get("isfilter")) ? true : !StringUtils.isEmpty((CharSequence)paramRefQueryInfo.getQueryCondition().get("isfilter"));
        if (isBoolean && isYear && !StringUtils.isEmpty(this.pk_budgetdept) && !StringUtils.isEmpty(this.pk_topbudgettype)) {
            this.year = Integer.valueOf((String)paramRefQueryInfo.getQueryCondition().get("year"));
            if (this.isfilter) {
                StringBuilder sql = new StringBuilder();
                sql.append(" and pk_project in ( ");
                sql.append(" select project.pk_project from hrpbm_dimassign mass ");
                sql.append(" left join hrpbm_dimassign_project project on mass.pk_dimassign = project.pk_dimassign ");
                sql.append(" where mass.nyear = '");
                sql.append(this.year);
                sql.append("' and mass.pk_budgetdept = '");
                sql.append(this.pk_budgetdept);
                sql.append("' and mass.pk_budgettype = (select PK_BUDGETTYPE from HRPBM_BUDGETTYPE where code ='");
                sql.append(this.pk_topbudgettype).append("' ))");
                extraSql = extraSql + sql.toString();
            }
            String appCode = ((TreeRefQueryInfo) paramRefQueryInfo).getAppCode();
            if("M0263015002".equals(appCode) || "M0263035".equals(appCode)){
                extraSql += " and pk_project in  ( select pk_PJAPPL from  HRPPL_PJAPPL where dr =  0 and officedept =  '"+  this.pk_budgetdept +"' and applyyear = '"+this.year+"' ) ";
            } return extraSql;
        } else {
            extraSql = extraSql + " and 1 = 1 ";
            return extraSql;
        }
    }

    public String[] getPk_orgs(RefQueryInfo paramRefQueryInfo) {
        if (StringUtils.isEmpty((CharSequence)paramRefQueryInfo.getQueryCondition().get("orgvos"))) {
            return new String[]{super.getPk_org(paramRefQueryInfo)};
        } else {
            String[] orgvos = ((String)paramRefQueryInfo.getQueryCondition().get("orgvos")).split(",");
            return orgvos;
        }
    }
}
